package com.lanhe.common.utils.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式
 * @author shangbin
 * @version v1.0
 * @date 2022/1/26 14:49
 **/
public class RegExUtil {

    /**
     * 校验手机号
     * @Description
     * @MethodName matchesPhone
     * @Param [mobile]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 14:50
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesMobile(String mobile) {
        Pattern p = Pattern.compile("^1(([3,6,7,8,9][0-9]{9})|(4[5,7][0-9]{8})|(5[0,1,2,3,5,6,7,8,9][0-9]{8})|(7(([0,5][0-9]{8})|([1,3,6,7,8][0-9]{8})))|(9[1,3,8,9][0-9]{8}))$");
        Matcher m = p.matcher(mobile);
        return m.matches();
    }

    /**
     * 校验银行卡
     * @Description
     * @MethodName matchesBankCard
     * @Param [bankCard]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:11
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesBankCard(String bankCard) {
        Pattern p = Pattern.compile("^[1-9][0-9]{15,18}$");
        Matcher m = p.matcher(bankCard);
        return m.matches();
    }

    /**
     * 校验身份证
     * @Description
     * @MethodName matchesCard
     * @Param [card]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:11
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesCard(String card) {
        Pattern p = Pattern.compile("^[1-9][0-9]{5}((19)|(20))[0-9]{2}((0[1-9])|(1[0-2]))((0[1-9])|([1,2][0-9])|(3[0-1]))[0-9]{3}[0-9xX]$");
        Matcher m = p.matcher(card);
        return m.matches();
    }

    /**
     * 校验日期
     * @Description
     * @MethodName matchesDate
     * @Param [date]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:12
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesDate(String date) {
        Pattern p = Pattern.compile("^((19)|(20))[0-9]{2}-(([1-9])|(0[1-9])|(1[0-2]))-(([1-9])|(0[1-9])|([1,2][0-9])|(3[0-1]))$");
        Matcher m = p.matcher(date);
        return m.matches();
    }

    /**
     * 校验日期时间
     * @Description
     * @MethodName matchesDateTime
     * @Param [dateTime]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:28
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesDateTime(String dateTime) {
        Pattern p = Pattern.compile("^((19)|(20))[0-9]{2}-(([1-9])|(0[1-9])|(1[0-2]))-(([1-9])|(0[1-9])|([1,2][0-9])|(3[0-1])) (([0-9])|([0-1][0-9])|(2[0-3])):(([0-9])|([0-5][0-9])):(([0-9])|([0-5][0-9]))$");
        Matcher m = p.matcher(dateTime);
        return m.matches();
    }

    /**
     * 校验电子邮件
     * @Description
     * @MethodName matchesEmail
     * @Param [email]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:28
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesEmail(String email) {
        Pattern p = Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
        Matcher m = p.matcher(email);
        return m.matches();
    }

    /**
     * 校验整数
     * @Description
     * @MethodName matchesInteger
     * @Param [integer]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:28
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesInteger(String integer) {
        Pattern p = Pattern.compile("^[-]?[\\d]+$");
        Matcher m = p.matcher(integer);
        return m.matches();
    }

    /**
     * 校验ip
     * @Description
     * @MethodName matchesIp
     * @Param [ip]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:28
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesIp(String ip) {
        Pattern p = Pattern.compile("^[1-9][\\d]{0,2}(.((0)|([1-9][\\d]{0,2}))){3}$");
        Matcher m = p.matcher(ip);
        return m.matches();
    }

    /**
     * 校验数字
     * @Description
     * @MethodName matchesNumber
     * @Param [number]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:28
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesNumber(String number) {
        Pattern p = Pattern.compile("^[\\d]+$");
        Matcher m = p.matcher(number);
        return m.matches();
    }

    /**
     * 校验数字
     * @Description
     * @MethodName matchesNumeric
     * @Param [numeric]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:28
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesNumeric(String numeric) {
        Pattern p = Pattern.compile("^[-]?[\\d]+(\\.[\\d]{1,12})?$");
        Matcher m = p.matcher(numeric);
        return m.matches();
    }

    /**
     * 校验邮政编码
     * @Description
     * @MethodName matchesPostcode
     * @Param [postcode]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:28
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesPostcode(String postcode) {
        Pattern p = Pattern.compile("^[\\d]{6}$");
        Matcher m = p.matcher(postcode);
        return m.matches();
    }

    /**
     * 校验qq
     * @Description
     * @MethodName matchesQq
     * @Param [qq]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:28
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesQq(String qq) {
        Pattern p = Pattern.compile("^[1-9][\\d]{4,9}$");
        Matcher m = p.matcher(qq);
        return m.matches();
    }

    /**
     * 校验电话
     * @Description
     * @MethodName matchesTel
     * @Param [tel]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:29
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesTel(String tel) {
        Pattern p = Pattern.compile("^0[1-9][0-9]{1,2}-[1-9][0-9]{6,7}(-[0-9]{1,4})?$");
        Matcher m = p.matcher(tel);
        return m.matches();
    }

    /**
     * 校验免费电话
     * @Description
     * @MethodName matchesTelFree
     * @Param [telFree]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:29
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesTelFree(String telFree) {
        Pattern p = Pattern.compile("^(400)|(800)[\\d]{7}$");
        Matcher m = p.matcher(telFree);
        return m.matches();
    }

    /**
     * 校验时间
     * @Description
     * @MethodName matchesTime
     * @Param [time]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:29
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesTime(String time) {
        Pattern p = Pattern.compile("^(([0-9])|([0-1][0-9])|(2[0-3])):(([0-9])|([0-5][0-9])):(([0-9])|([0-5][0-9]))$");
        Matcher m = p.matcher(time);
        return m.matches();
    }

    /**
     * 校验网址
     * @Description
     * @MethodName matchesUrl
     * @Param [url]
     * @ReturnType java.lang.Boolean
     * @Date  2022/1/26 15:29
     * @Author shang
     * @Since 1.0
     */
    public static Boolean matchesUrl(String url) {
        Pattern p = Pattern.compile("^((http(s)?:\\/\\/)([\\w-]+\\.)+)|((file:\\/\\/\\/)[\\w-]+)$");
        Matcher m = p.matcher(url);
        return m.matches();
    }

    /**
     * @Description 校验账号数字+字母或者纯字母 不能纯数字  6-20
     * @MethodName matchesAccount
     * @Param [account]
     * @ReturnType java.lang.Boolean
     * @Date  2022/10/13 17:09
     * @Author zxx
     * @Since 1.0
     */
    public static Boolean matchesAccount(String account) {
        Pattern p = Pattern.compile("^(?![0-9]+$)[0-9A-Za-z]{6,20}$");
        Matcher m = p.matcher(account);
        return m.matches();
    }

    /**
     * @Description 校验密码，字母+数字+特殊字符  中任意两种组合
     * @MethodName matchesPassword
     * @Param [password]
     * @ReturnType java.lang.Boolean
     * @Date  2022/10/13 17:15
     * @Author zxx
     * @Since 1.0
     */
    public static Boolean matchesPassword(String password) {
        Pattern p = Pattern.compile("^(?![a-zA-Z]+$)(?!\\d+$)(?![^\\da-zA-Z\\s]+$).{6,20}$");
        Matcher m = p.matcher(password);
        return m.matches();
    }

    /**
     * @Description 校验二级域名 数字+字母或者纯字母 不能纯数字  2-20 长度
     * @MethodName matchesSubDomain
     * @Param [account]
     * @ReturnType java.lang.Boolean
     * @Date  2022/10/15 10:45
     * @Author zxx
     * @Since 1.0
     */
    public static Boolean matchesSubDomain(String account) {
        Pattern p = Pattern.compile("^(?![0-9]+$)[0-9A-Za-z]{2,20}$");
        Matcher m = p.matcher(account);
        return m.matches();
    }


    /**
     * @Description 校验社会信用代码
     * @MethodName matchesSocialCreditCode
     * @Param
     * @ReturnType
     * @Date  2023/8/25
     * @Author xiaoliujun
     * @Since 1.0
     */
    public static Boolean matchesSocialCreditCode(String socialCreditCode) {
        Pattern p = Pattern.compile("^([0-9A-HJ-NPQRTUWXY]{2}\\d{6}[0-9A-HJ-NPQRTUWXY]{10}|[1-9]\\d{14})$");
        Matcher m = p.matcher(socialCreditCode);
        return m.matches();
    }


    public static void main(String[] args) {
        System.out.println(matchesEmail("13018177@qcom"));
    }

}
